request = require 'needle'
ndir = require('ndir')

lineNumber = 0
i = 0
ndir.createLineReader('./ip.txt').on 'line', (line) ->
  line = line.toString()
  setTimeout ->
    do (line) ->
      data =
        id: '7169'
        'content_type' : 'application/x-www-form-urlencoded'

      options =
        timeout: 5000
        proxy: "http://#{line}"
        user_agent: 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1) Gecko/20020826' + line
        compressed: true
        follow_set_cookies:true
      request
      .post 'http://open.liveapp.cn/contest/entries/add_vote', data , options, (err, res) ->
        return if err?
        json ={}
        # console.log line.toString()
        try
          json = JSON.parse res.body if res.body?
          console.log json
          if json.success? and json.success
            console.log ++i
        catch e
         # return console.log 'err'
  , 2000


.on 'end', ->
  console.log('read a file done.')
.on 'error',  (err) ->
  console.log('error: ', err.message)



